//---------------------------------------------------------------------------
// UTF-8 Test
// Author : Woo-Hyun Kim at www.webrobot.org
// Email : woorung@webrobot.org or webrobot@hotmail.com
// Date : Jan. 28, 2002
//---------------------------------------------------------------------------
#include "CXCode.h"
//---------------------------------------------------------------------------
int main(int argc, char *argv[])
{
  string sStr = argv[1];
  string ctype = "ksc5601";

    int iKscBufSize;
    int iKscHexBufSize;
    int iUnicodeWideBufSize;
    int iUnicodeHexBufSize;
    int iUtf8BufSize;
    int iUtf8HexBufSize;

    unsigned char *szKsc;
    unsigned char *szKscHex;
    unsigned short *uUnicode;
    unsigned char *szUnicodeHex;
    unsigned char *szUtf8;
    unsigned char *szUtf8Hex;

    CXCode *EncodeX = new CXCode();

    if(ctype=="ksc5601") {  // KSC5601 input
      szKsc = (unsigned char *) sStr.c_str();
      // ksc5601
	cout << "[ksc5601]" << sStr << endl;
      // ksc5601 to hexcode
      iKscHexBufSize = EncodeX->GetKscToKscHexBufSize(szKsc);
      szKscHex = new unsigned char[iKscHexBufSize];
      szKscHex = EncodeX->KscToHex(szKscHex);
	cout << "[ksc hex]" << (string) (char *) szKscHex << endl;
      delete []szKscHex;
      // unicode
      iUnicodeWideBufSize = EncodeX->GetKscToUnicodeWideBufSize(szKsc);
      uUnicode = new unsigned short[iUnicodeWideBufSize];
      uUnicode = EncodeX->KscToUnicode(uUnicode);
	cout << "[unicode]" << (string) (char *) uUnicode << endl;
      //delete []uUnicode;
      // unicode to hexcode
      iUnicodeHexBufSize = EncodeX->GetKscToUnicodeHexBufSize(szKsc);
      szUnicodeHex = new unsigned char[iUnicodeHexBufSize];
      szUnicodeHex = EncodeX->UnicodeToHex(uUnicode,szUnicodeHex);
      delete []uUnicode;
	cout << "[unicode hex]" << (string) (char *) szUnicodeHex << endl;
      delete []szUnicodeHex;
      // utf8
      iUtf8BufSize = EncodeX->GetKscToUtf8BufSize(szKsc);
      szUtf8 = new unsigned char[iUtf8BufSize];
      szUtf8 = EncodeX->KscToUtf8(szUtf8);
	cout << "[utf8]" << (string) (char *) szUtf8 << endl;
      //delete []szUtf8;
      // utf8 to hexcode
      iUtf8HexBufSize = EncodeX->GetKscToUtf8HexBufSize(szKsc);
      szUtf8Hex = new unsigned char[iUtf8HexBufSize];
      szUtf8Hex = EncodeX->Utf8ToHex(szUtf8,szUtf8Hex);
      delete []szUtf8;
	cout << "[utf8 hex]" <<  (string) (char *) szUtf8Hex << endl;
      delete []szUtf8Hex;
    }
    else if(ctype=="unicode") {  // Unicode input
      szKsc = (unsigned char *)sStr.c_str();

      // unicode
      iUnicodeWideBufSize = EncodeX->GetKscToUnicodeWideBufSize(szKsc);
      uUnicode = new unsigned short[iUnicodeWideBufSize];
      uUnicode = EncodeX->KscToUnicode(uUnicode);
	cout << "[unicode]" << (string) (char *) uUnicode << endl;
      //delete []uUnicode;
      // unicode to hexcode

      iUnicodeHexBufSize = EncodeX->GetUnicodeToUnicodeHexBufSize(uUnicode);
      szUnicodeHex = new unsigned char[iUnicodeHexBufSize];
      szUnicodeHex = EncodeX->UnicodeToHex(uUnicode,szUnicodeHex);
	cout << "[unicode hex]" << (string) (char *) szUnicodeHex << endl;
      delete []szUnicodeHex;
      // ksc5601
      iKscBufSize = EncodeX->GetUnicodeToKscBufSize(uUnicode);
      szKsc = new unsigned char[iKscBufSize];
      szKsc = EncodeX->UnicodeToKsc(szKsc);
	cout << "[ksc5601]" << (string) (char *) szKsc << endl;
      //delete []szKsc;

      // ksc5601 to hexcode
      iKscHexBufSize = EncodeX->GetUnicodeToKscHexBufSize(uUnicode);
      szKscHex = new unsigned char[iKscHexBufSize];
      szKscHex = EncodeX->KscToHex(szKsc,szKscHex);
      delete []szKsc;
	cout << "[ksc5601 hex]" << (string) (char *) szKscHex << endl;
      delete []szKscHex;

      // utf8
      iUtf8BufSize = EncodeX->GetUnicodeToUtf8BufSize(uUnicode);
      szUtf8 = new unsigned char[iUtf8BufSize];
      szUtf8 = EncodeX->UnicodeToUtf8(szUtf8);
	cout << "[utf8]" << (string) (char *) szUtf8 << endl;
      //delete []szUtf8;
      // utf8 to hexcode
      iUtf8HexBufSize = EncodeX->GetUnicodeToUtf8HexBufSize(uUnicode);
      szUtf8Hex = new unsigned char[iUtf8HexBufSize];
      szUtf8Hex = EncodeX->Utf8ToHex(szUtf8,szUtf8Hex);
      delete []szUtf8;
	cout << "[utf8 hex]" << (string) (char *) szUtf8Hex << endl;
      delete []szUtf8Hex;

      delete []uUnicode;
    }
    else if(ctype=="utf8") {  // UTF-8 input
      szKsc = (unsigned char *)sStr.c_str();
      // utf8
      iUtf8BufSize = EncodeX->GetKscToUtf8BufSize(szKsc);
      szUtf8 = new unsigned char[iUtf8BufSize];
      szUtf8 = EncodeX->KscToUtf8(szUtf8);
	cout << "[utf8]" << (string) (char *) szUtf8 << endl;
      //delete []szUtf8;
      // utf8 to hexcode
      iUtf8HexBufSize = EncodeX->GetUtf8ToUtf8HexBufSize(szUtf8);
      szUtf8Hex = new unsigned char[iUtf8HexBufSize];
      szUtf8Hex = EncodeX->Utf8ToHex(szUtf8,szUtf8Hex);
      //delete []szUtf8;
	cout << "[utf8 hex]" << (string) (char *) szUtf8Hex << endl;
      delete []szUtf8Hex;
      // ksc5601
      iKscBufSize = EncodeX->GetUtf8ToKscBufSize(szUtf8);
      szKsc = new unsigned char[iKscBufSize];
      szKsc = EncodeX->Utf8ToKsc(szUtf8,szKsc);
	cout << "[ksc5601]" << (string) (char *) szKsc << endl;
      //delete []szKsc;
      // ksc5601 to hexcode
      iKscHexBufSize = EncodeX->GetUtf8ToKscHexBufSize(szUtf8);
      szKscHex = new unsigned char[iKscHexBufSize];
      szKscHex = EncodeX->KscToHex(szKsc,szKscHex);
      delete []szKsc;
	cout << "[ksc5601 hex]" << (string) (char *) szKscHex << endl;
      delete []szKscHex;
      // unicode
      iUnicodeWideBufSize = EncodeX->GetUtf8ToUnicodeWideBufSize(szUtf8);
      uUnicode = new unsigned short[iUnicodeWideBufSize];
      uUnicode = EncodeX->Utf8ToUnicode(szUtf8,uUnicode);
	cout << "[unicode]" << (string) (char *) uUnicode << endl;
      //delete []uUnicode;
      // unicode to hexcode
      iUnicodeHexBufSize = EncodeX->GetUtf8ToUnicodeHexBufSize(szUtf8);
      szUnicodeHex = new unsigned char[iUnicodeHexBufSize];
      szUnicodeHex = EncodeX->UnicodeToHex(uUnicode,szUnicodeHex);
      delete []uUnicode;
	cout << "[unicode hex]" << (string) (char *) szUnicodeHex << endl;
      delete []szUnicodeHex;

      delete []szUtf8;
    }

    delete EncodeX;
}
//---------------------------------------------------------------------------
